package com.colin.aiyi.presenter.Imp;

import com.colin.aiyi.app.Constant;
import com.colin.aiyi.dao.ImpxUtils.AbsServicexUtils;
import com.colin.aiyi.entity.BaseRequest;
import com.colin.aiyi.entity.WXResponse;
import com.colin.aiyi.presenter.Interface.Callback;

import org.xutils.http.RequestParams;

/**
 * Created by hl on 2017/6/21.
 */

public class ImpWXAccessTonken extends AbsServicexUtils {

    @Override
    public void onSuccess(String result) {
        super.onSuccess(result);
        WXResponse wxResponse=gson.fromJson(result,WXResponse.class);
        if (callback==null)
        {
            sendMsgToView(wxResponse);
        }else {
            callback.onSuccess(wxResponse);
        }
    }

    public <T, V> void getWXAccessTonken(Callback<T> t, V v) {
        this.callback=t;
        getWXAccessTonken(v);
    }

    /*********
     * 获取微信openID ，accessToken
     * @param
     */

    public <T, V> void getWXAccessTonken( V v) {
        BaseRequest baseRequest= (BaseRequest) v;
        RequestParams params=new RequestParams("https://api.weixin.qq.com/sns/oauth2/access_token");
        params.addBodyParameter("appid",Constant.APP_ID);
        params.addBodyParameter("secret",Constant.WX_SWCRET);
        params.addBodyParameter("code",baseRequest.getCode());
        params.addBodyParameter("grant_type","authorization_code");
        sendToServer(params);
    }


}




